package ${businessPackagePath}.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import ${businessPackagePath}.service.${changeTableName}Service;
import ${entityPackagePath}.${changeTableName};
import ${entityPackagePath}.${changeTableName}Vo;
import ${entityPackagePath}.${changeTableName}UpdateDto;
import ${entityPackagePath}.${changeTableName}SelectDto;
import ${entityPackagePath}.${changeTableName}InsertDto;
import com.hchl.org.graphics.utils.SystemConstant;
import com.hchl.org.graphics.common.entity.common.BatchDeleteIdVo;
import com.hchl.org.graphics.utils.Res;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ${author}
 * @url https://gitee.com/pucong
 * @create ${date}
 */
@RestController
@RequestMapping("/${modelPath}/${changeTableName?uncap_first}")
@Api(tags = "${tableAnnotation}-API ")
public class ${changeTableName}Controller {

    @Autowired
    private ${changeTableName}Service ${changeTableName?uncap_first}Service;

    @GetMapping("/get${changeTableName}ListByPage/{pageNum}/{pageSize}")
    @ApiOperation(value = "分页条件查询")
    public Res<IPage<${changeTableName}Vo>> get${changeTableName}ListByPage(@ApiParam(value = "页数",example = "1")@PathVariable("pageNum") int pageNum,@ApiParam(value = "一页大小",example = "10")@PathVariable("pageSize") int pageSize,${changeTableName}SelectDto ${changeTableName?uncap_first}SelectDto){
        IPage ${changeTableName?uncap_first}PageList = ${changeTableName?uncap_first}Service.get${changeTableName}ListByPage(pageNum,pageSize,${changeTableName?uncap_first}SelectDto);
        return Res.ok(${changeTableName?uncap_first}PageList);
    }

    @GetMapping("/get${changeTableName}List")
    @ApiOperation(value = "不分页条件查询")
    public Res<List<${changeTableName}Vo>> get${changeTableName}List(${changeTableName}SelectDto ${changeTableName?uncap_first}SelectDto){
        List<${changeTableName}Vo> ${changeTableName?uncap_first}List = ${changeTableName?uncap_first}Service.get${changeTableName}List(${changeTableName?uncap_first}SelectDto);
        return Res.ok(${changeTableName?uncap_first}List);
    }

    @GetMapping("/get${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键查询详情")
    public Res<${changeTableName}Vo> get${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id){
        ${changeTableName}Vo ${changeTableName?uncap_first}Dto = ${changeTableName?uncap_first}Service.get${changeTableName}ById(id);
        return Res.ok(${changeTableName?uncap_first}Dto);
    }

    @PostMapping("/insert${changeTableName}")
    @ApiOperation(value = "新增")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "新增个数")
    })
    public Res<Integer> insert${changeTableName}(@Validated @RequestBody ${changeTableName}InsertDto ${changeTableName?uncap_first}InsertDto){
        int i = ${changeTableName?uncap_first}Service.insert${changeTableName}(${changeTableName?uncap_first}InsertDto);
        return Res.ok(i);
    }

    @PutMapping("/update${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键更新数据")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "修改个数")
    })
    public Res<Integer> update${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id,@RequestBody ${changeTableName}UpdateDto ${changeTableName?uncap_first}UpdateDto){
        int i = ${changeTableName?uncap_first}Service.update${changeTableName}ById(id,${changeTableName?uncap_first}UpdateDto);
        return Res.ok(i);
    }

    @DeleteMapping("/delete${changeTableName}ById/{id}")
    @ApiOperation(value = "根据主键删除数据")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "删除个数")
    })
    public Res<Integer> delete${changeTableName}ById(@ApiParam("主键")@PathVariable("id") String id){
        int i = ${changeTableName?uncap_first}Service.delete${changeTableName}ById(id);
        return Res.ok(i);
    }

    @DeleteMapping("/batchDelete${changeTableName}ByIds")
    @ApiOperation(value = "批量删除数据")
    @ApiResponses({
        @ApiResponse(code = SystemConstant.CODE_OK,message = "删除个数")
    })
    public Res<Integer> batchDelete${changeTableName}ByIds(BatchDeleteIdVo batchDeleteIdVo){
        int i = ${changeTableName?uncap_first}Service.batchDelete${changeTableName}ByIds(batchDeleteIdVo.getIdList());
        return Res.ok(i);
    }
}